<template>
	<view class="software-use">
		<view class="week-use-line">
			<view class="title">最近7天软件使用情况</view>
			<qiun-data-charts 
					type="line" 
					:chartData="weekUseData" 
				/>
		</view>
		<view class="year-use-pie">
			<view class="title">今年软件使用情况</view>
			<qiun-data-charts
			    type="pie"
			    :chartData="yearUsePieData"
			    background="none"
			  />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				weekUseData: {
				  categories: [],
				  series: []
				},
				yearUsePieData: {
					series:[
						{
							data: []
						}
					]
				}
			}
		},
		methods: {
			async getWeekUseTime() {
				const res = await this.$myRequest({ url: '/software/time/weekStatistic' })
				
				// x轴
				this.weekUseData.categories = res.data.dateList
				console.log(this.weekUseData.series)
				
				// 数据
				res.data.useTimeDoList.forEach(ut => {
				  this.weekUseData.series.push({
				    name: ut.softwareName,
				    data: ut.useTimeList
				  })
				})
			},
			async getYearUseTime() {
				const res = await this.$myRequest({ url: '/software/time/yearStatistic' })
				
				// 数据
				res.data.forEach(data => {
				  this.yearUsePieData.series[0].data.push({
				    name: data.softwareName,
				    value: data.useTimeLength
				  })
				})
			}
		},
		onLoad() {
			this.getWeekUseTime()
			this.getYearUseTime()
		}
	}
</script>

<style scoped lang="scss">
	.software-use {
		width: 750rpx;
		.week-use-line {
			width: 100%;
			margin-top: 20rpx;
			.title {
				text-align: center;
				height: 80rpx;
				line-height: 80rpx;
				font-size: 36rpx;
				font-weight: bold;
			}
		}
		.year-use-pie {
			width: 100%;
			margin-top: 20rpx;
			.title {
				text-align: center;
				height: 80rpx;
				line-height: 80rpx;
				font-size: 36rpx;
				font-weight: bold;
			}
		}
	}
</style>
